import ctime from '@/components/changeTime.vue'
import { AddMobileContactData } from '@/utils/common-api.js'
export default {
  data() {
    return {
      // Core,
      id: '',
      dataObj: { findBoffList: [] },
      offerCountList: ['已报价', '待确认合同', '已过期'],
      onShelfTime: '', //上架时间
      dataList: [], //继续寻车列表
      pageFrom: '', //从哪里进入详情
    }
  },
  onLoad(option) {
    this.id = option.id
    this.pageFrom = option.pageFrom ? option.pageFrom : ''
    this.store = this.$store.state.userInfoDetail.store.storeId
    this.getPageDetail()

    this.getFindCarList()
  },
  components: {
    ctime,
  },
  computed: {},
  methods: {
    goDetail() {
      uni.navigateTo({
        url:
          '/pages_findCar/detailsInqParticipation/detailsInqParticipation?id=' +
          this.id,
      })
    },
    async getPageDetail() {
      try {
        let data = {
          id: this.id,
          store_Id: this.store,
        }
        const res = await this.$api.findCar.GetMyCarFindBDetails(data)
        console.log(res)
        res.data.facade_pictureList.forEach((item) => {
          if (item.inColour) {
            item.inColour.neiColor = item.inColour.colorCoding
              ? item.inColour.colorCoding.split('/')
              : []
          }
          if (item.outerColour) {
            item.outerColour.neiColor = item.outerColour.colorCoding
              ? item.outerColour.colorCoding.split('/')
              : []
          }
        })
        this.dataObj = res.data
      } catch (e) {
        //TODO handle the exception
      }
    },
    // 获取继续报价列表
    async getFindCarList() {
      let data = {
        pageIndex: 1,
        pageSize: 3,
        search: '',
        brand: '',
        specification: 0,
        region_Limit_Id: '',
        store_Id: this.$store.state.userInfoDetail.store.storeId,
      }

      try {
        const res = await this.$api.findCar.GetCarFindBList(data)

        this.loadmore = 0
        res.data.list.forEach((it) => {
          it.facade_Picture.forEach((item) => {
            if (item.inColour) {
              item.inColour.neiColor = item.inColour.colorCoding
                ? item.inColour.colorCoding.split('/')
                : []
            }
            if (item.outerColour) {
              item.outerColour.neiColor = item.outerColour.colorCoding
                ? item.outerColour.colorCoding.split('/')
                : []
            }
          })
        })
        this.dataList = this.dataList.concat(res.data.list)
      } catch (err) {
        console.log(err)
      }
    },
    // 跳转到店铺
    goStore() {
      uni.navigateTo({
        url: '/pages_common/store/store?id=' + this.dataList.store_id,
      })
    },
    //联系买家
    contactSeller() {
      if (this.pageFrom === 'chat') {
        uni.navigateBack()
        return
      }
      // 传和我聊天人的信息
      this.$store.commit('news/createConversationActive', {
        user: this.dataObj.store_Name, //店铺名称
        img: this.dataObj.store_Topimg, //店铺头像
        lastTime: '', //
        userId: this.dataObj.store_id, //店铺id
        conversationID: 'C2C' + this.dataObj.store_id,
      })
      this.$store.commit('news/setCardInfo', {
        imgSrc: this.dataObj.car_TypeUrl,
        name: this.dataObj.car_type_name + ' ' + this.dataObj.car_name,
        price:
          (
            this.dataObj.carFindBOneselfDetailsBoffPublicSon.quoted_Price /
            10000
          ).toFixed(2) + '万',
        labelPrige: this.dataObj.price,
        type: 'findCar',
      })
      uni.navigateTo({
        url:
          '/pages_news/contactSeller/contactSeller?user=' +
          this.dataObj.store_Name +
          '&pageId=' +
          this.dataObj.id +
          '&tab=0',
      })
    },
    //打电话
    phoneClick() {
      console.log(this.dataObj.mobile)
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      uni.makePhoneCall({
        phoneNumber: this.dataObj.mobile, //仅为示例
      })
    },
    // 返回优惠价
    returnDifference(val) {
      if (val) {
        return val.split('-')[1]
      }
    },
    //寻车详情 /编辑寻车
    Findcardetails(val, type, add) {
      let id = '',
        store = ''
      if (add === 1) {
        id = val.id
        store = val.store_Id
      } else {
        id = this.id
        store = this.store
      }

      uni.navigateTo({
        url:
          '/pages_findCar/noQuotationForFindCar/noQuotationForFindCar?id=' +
          id +
          '&storeId=' +
          store +
          '&type=' +
          type +
          '&goIn=' +
          add,
      })
    },

    returnTime(val) {
      if (val) {
        return val.split('T')[0] + ' ' + val.split('T')[1]
      }
    },
  },
}
